package xyz.yuzegod.megawalls.timer;

import org.bukkit.Sound;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.game.GamePlayer;

public class SkillTimer implements Runnable
{
    private int tick;
    
    public SkillTimer() {
        this.tick = 0;
    }
    
    @Override
    public void run() {
        for (final GamePlayer gamePlayer : MegaWalls.getIngame()) {
            if (gamePlayer.getEnergy() == 100) {
                gamePlayer.getPlayer().setLevel(gamePlayer.getEnergy());
                gamePlayer.getPlayer().setExp((gamePlayer.getPlayer().getExp() >= 1.0f) ? 0.0f : 1.0f);
                if (this.tick % 600 == 0) {
                    gamePlayer.sendMessage("§a你的§b§l" + gamePlayer.getPlayerStats().getSelected().getMainSkill().getName() + "§a技能已就绪！");
                    gamePlayer.sendMessage("§b点击§a任意的剑或弓来激活你的技能！");
                    gamePlayer.playSound(Sound.LAVA_POP, 1.0f, 1.0f);
                }
                this.tick += 5;
            }
            else {
                gamePlayer.getPlayer().setLevel(gamePlayer.getEnergy());
                gamePlayer.getPlayer().setExp(gamePlayer.getEnergy() / 100.0f);
            }
        }
        this.tick += 5;
    }
}
